using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using Microsoft.Extensions.Configuration;
using Microsoft.EntityFrameworkCore;
using AJAXCore.Repositories;
using AJAXCore.Data;
using AJAXCore.Middleware;

namespace AJAXCore {
  public class Startup {
    private IConfiguration _configuration;

    public Startup(IConfiguration configuration) {
      _configuration = configuration;
    }

    public void ConfigureServices(IServiceCollection services) {
      services.AddDbContext<MyDBContext>(options =>
                 options.UseSqlServer(_configuration.GetConnectionString("MyDB")));

      services.AddScoped<IRepository,Repository>();
      services.AddMvc();
    }

    public void Configure(IApplicationBuilder app, MyDBContext personContext,IHostingEnvironment env) {
      //personContext.Database.EnsureDeleted();
      personContext.Database.EnsureCreated();

      app.UseStaticFiles();
      app.UseNodeModules(env.ContentRootPath);
      //app.UseMvcWithDefaultRoute();
    }
  }
}
